package com.jw.springcloud.controller;

import com.jw.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author jiangwang
 * @Created by 2021/3/23 16:15
 * @Description: TODO
 */
@RestController
public class DeptConsumerController {

    @Autowired
    private RestTemplate restTemplate;

//    private static final String REST_URL = "http://localhost:8001";

    // Ribbon 通过变量，服务名去访问
    private static final String REST_URL = "http://springcloud-provider-dept";

    @RequestMapping("/consumer/add")
    public boolean add(Dept dept){
        return restTemplate.postForObject(REST_URL+"/addDept/",dept,Boolean.class);
    }

    @RequestMapping("/consumer/get/{id}")
    public Dept get(@PathVariable("id") Long id){
        return restTemplate.getForObject(REST_URL+"/queryById/"+id,Dept.class);
    }

    @RequestMapping("/consumer/getList")
    public List getList(){
        return restTemplate.getForObject(REST_URL+"/queryAll",List.class);
    }

}
